package org.dictionary;


import org.springframework.beans.factory.annotation.Autowired;
import org.ydsw.data.manage.mapper.DealDictionaryEntityMapper;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: zhongShanfeng
 * @date: 2023年12月28日 上午 11:05
 * @Description: 解析txt文件获取里面的数据
 * 将txt文件里面的内容，解析成对象，添加到表里去
 */
public class DealDictionary {
    public static void main(String[] args) {

        new DealDictionary().parseTxt3();

    }

    private void parseTxt3() {
        BufferedReader reader = null;
        try {
            InputStreamReader read = new InputStreamReader(new FileInputStream("E:\\DataDictionary\\dataStanrd1.csv"), "UTF-8");
            reader = new BufferedReader(read);
            String line = null;

            String tableEnName = "";
            String tableChName = "";
            while((line =reader.readLine()) != null){
                String[] split = line.split(",");
                String contactStr = "`"+split[0]+"`"+" String "+"COMMENT "+"'"+split[1]+"'"+",";
                System.out.println(contactStr);

//

            }



        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private void parseTxt2() {
            BufferedReader reader = null;
            try {
                InputStreamReader read = new InputStreamReader(new FileInputStream("C:\\Users\\Zhong\\Desktop\\big_table.sql"), "UTF-8");
                reader = new BufferedReader(read);
                String line = null;
                while((line =reader.readLine()) != null){

                    String[] split = line.split("\t");
                    String contactStr = "`"+split[0]+"`"+" String "+"COMMENT "+"'"+split[1]+"'"+",";
                    System.out.println(contactStr);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

    }
    private void parseTxt() {
        BufferedReader reader = null;
        try {
            InputStreamReader read = new InputStreamReader(new FileInputStream("E:\\DataDictionary\\EasDataDictionary.csv"), "UTF-8");
            reader = new BufferedReader(read);
            String line = null;
            List<DealDictionaryEntity> dealDictionarys = new ArrayList<>();
            String tableEnName = "";
            String tableChName = "";
            while((line =reader.readLine()) != null){
//                line = reader.readLine();
                System.out.println(line);
//                System.out.println(line);
                DealDictionaryEntity dealDictionaryEntity = new DealDictionaryEntity();
                String[] split = line.split(",");
                System.out.println(split.length);
                if (split[0].contains("（") && line.contains("）")) {
                    tableEnName = line.substring(0, line.indexOf("（"));
                    tableChName = line.substring(line.indexOf("（"));
                    continue;
                }

                switch (split.length){
                    case 6:{
                        dealDictionaryEntity.setTableName(tableEnName);
                        dealDictionaryEntity.setTableChName(tableChName.substring(tableChName.indexOf("（")+1,tableChName.indexOf("）")));
                        dealDictionaryEntity.setFieldName(split[0]);
                        dealDictionaryEntity.setFieldSecondaryName(split[1]);
                        dealDictionaryEntity.setDataType(split[2]);
                        dealDictionaryEntity.setDataLength(split[3]);
                        dealDictionaryEntity.setDataAccuracy(split[4]);
                        dealDictionaryEntity.setDataDecimalCount(split[5]);
                        break;
                    }
                    case 7:{
                        dealDictionaryEntity.setTableName(tableEnName);
                        dealDictionaryEntity.setTableChName(tableChName.substring(tableChName.indexOf("（")+1,tableChName.indexOf("）")));
                        dealDictionaryEntity.setFieldName(split[0]);
                        dealDictionaryEntity.setFieldSecondaryName(split[1]);
                        dealDictionaryEntity.setDataType(split[2]);
                        dealDictionaryEntity.setDataLength(split[3]);
                        dealDictionaryEntity.setDataAccuracy(split[4]);
                        dealDictionaryEntity.setDataDecimalCount(split[5]);
                        dealDictionaryEntity.setDataTips(split[6]);
                        break;
                    }
                }
                dealDictionarys.add(dealDictionaryEntity);
            }
            dealDictionarys.forEach(System.out::println);


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}

